{{Extend "layout"}} {{Block "title"}}{{"服务端配置"|T}}{{/Block}} {{Block "breadcrumb"}} {{Super}}
<li class="active">{{"服务端配置"|T}}</li>
{{/Block}} {{Block "main"}}
<div class="row">
	<div class="col-md-12">
		<div class="block-flat">
			<div class="header">
				<div class="alert alert-warning">
					<i class="fa fa-lightbulb-o text-warning"></i>
					1. {{"此处将会启动所有“启用”状态的配置"|T}}
					&nbsp; 
					2. {{"请将用不到的配置设置为禁用"|T}}
				</div>
				<div class="pull-right" style="margin-left:10px">
					<form class="form-horizontal" action="" id="search-form" method="GET">
						<div class="input-group">
							<span class="input-group-addon">{{"分组"|T}}</span>
							<select name="groupId" class="form-control" id="groupId" onchange="$('#search-form').submit()">
								<option value="0"> - {{"不限"|T}} - </option>
								{{$groupId := Stored.groupId}} 
								{{range $k, $v := Stored.groupList}}
								<option value="{{$v.Id}}" {{if eq $groupId $v.Id}} selected{{end}}>{{$v.Name}}</option>
								{{end}}
							</select>
						</div>
					</form>
				</div>
				<button data-url="__BACKEND__/frp/server_stop" id="ctrl-server-stop" class="btn btn-warning btn-flat pull-right">
					<i class="fa fa-power-off"></i>
					{{"关闭服务端"|T}}
				</button>
				<button data-url="__BACKEND__/frp/server_restart" id="ctrl-server-restart" class="btn btn-{{if Stored.isRunning}}info{{else}}success{{end}} pull-right">
					{{if Stored.isRunning}}
					<i class="fa fa-refresh"></i>
					{{"重启服务端"|T}}
					{{else}}
					<i class="fa fa-play"></i>
					{{"启动服务端"|T}}
					{{end}}
				</button>
				<a href="__BACKEND__/frp/server_add" class="btn btn-default pull-right">
					<i class="fa fa-plus"></i>
					{{"添加配置"|T}}
				</a>
				<h3>{{"服务端配置列表"|T}}
				</h3>
			</div>
			<div class="content">
				<div class="table-responsive">
					<table class="table no-border hover">
						<thead class="no-border">
							<tr>
								<th style="width:2%;">
									<strong>ID</strong>
								</th>
								<th>
									<strong>{{"名称"|T}}</strong>
								</th>
								<th>
									<strong>{{"监听地址"|T}}</strong>
								</th>
								<th>
									<strong>{{"虚拟主机"|T}}</strong>
								</th>
								<th>
									<strong>{{"日志输出"|T}}</strong>
								</th>
								<th style="width:15%;">
									<strong>{{"配置组"|T}}</strong>
								</th>
								<th style="width:15%;">
									<strong>{{"编辑时间"|T}}</strong>
								</th>
								<th style="width:80px"><strong>{{"运行状态"|T}}</strong></th>
								<th style="width:80px;"><strong>{{"启用状态"|T}}</strong></th>
								<th style="width:15%;" class="text-center">
									<strong>{{"操作"|T}}</strong>
								</th>
							</tr>
						</thead>
						<tbody class="no-border-y">
							{{range $k,$v := Stored.listData}}
							<tr>
								<td>{{$v.Id}}</td>
								<td>{{$v.Name}}</td>
								<td>{{$v.Addr}}:{{$v.Port}}</td>
								<td>
									{{if gt $v.VhostHttpPort 0}}
									HTTP: 
									<a href="http://127.0.0.1:{{$v.VhostHttpPort}}" target="_blank">{{$v.VhostHttpPort}}</a>
									<br />
									{{end}}
									{{if gt $v.VhostHttpsPort 0}}
									HTTPS: 
									<a href="https://127.0.0.1:{{$v.VhostHttpsPort}}" target="_blank">{{$v.VhostHttpsPort}}</a>
									{{end}}
								</td>
								<td>{{$v.LogWay}}</td>
								<td>{{if $v.Group}}{{$v.Group.Name}}{{else}}{{"无"|T}}{{end}}</td>
								<td>{{if gt $v.Updated 0}}{{(Date $v.Updated).Format "2006-01-02 15:04:05"}}{{else}}{{(Date $v.Created).Format "2006-01-02 15:04:05"}}{{end}}</td>
								<td>
									{{if $v.Running}}
									<span class="status-run fa fa-play text-success"> {{"运行中"|T}}</span>
									{{else}}
									<span class="status-run fa fa-stop text-danger"> {{"已停止"|T}}</span>
									{{end}}
								</td>
								<td>
								<div class="checkbox checkbox-primary no-margin-y">
									<input type="checkbox" id="checkbox-disabled-{{$k}}" value="N" class="switch-disabled" data-id="{{$v.Id}}" data-disabled="{{$v.Disabled}}"{{if eq $v.Disabled "N"}} checked="checked"{{end}} /> <label for="checkbox-disabled-{{$k}}">{{"启用"|T}}</label>
								</div>
								</td>
								<td class="text-center">
									<a class="label label-default" href="__BACKEND__/frp/server_add?copyId={{$v.Id}}" title="{{"复制"|T}}" data-toggle="tooltip"><i class="fa fa-copy"></i></a>
									<a class="label label-success" href="__BACKEND__/frp/server_edit?id={{$v.Id}}" title="{{"编辑"|T}}" data-toggle="tooltip"><i class="fa fa-pencil"></i></a>
									<a class="label label-danger" href="__BACKEND__/frp/server_delete?id={{$v.Id}}" onclick="return confirm('{{"真的要删除吗？"|T}}');" title="{{"删除"|T}}" data-toggle="tooltip"><i class="fa fa-times"></i></a>
								</td>
							</tr>
							{{end}}
						</tbody>
					</table>
				</div>
				{{Stored.pagination.Render}}
			</div>
		</div>
	</div>
</div>
{{/Block}}
{{Block "footer"}}
<script>
$(function(){
	$('#ctrl-server-restart,#ctrl-server-stop').on('click',function(){
		var isRe=$(this).attr('id')=='ctrl-server-restart',me=$(this);
		$.get($(this).data('url'),{},function(r){
			if(r.Code==1){
				window.setTimeout(function(r){
					window.location.reload();
				},1000);
			}
			var title=me.text().replace(/^[\s]+|[\s]+$/g,'');
			App.message({title:title,text:r.Info,time:5000,sticky:false,class_name:r.Code==1?'success':'error'});
		},'json');
	});
	$('input.switch-disabled').on('click',function(r){
		var that=$(this),disabled=that.data('disabled')=='Y'?'N':'Y';
		$.get(BACKEND_URL+'/frp/server_edit',{
			disabled:disabled,
			id:that.data('id')
		},function(r){
			if(r.Code==1){
				that.data('disabled',disabled);
				that.prop('checked',disabled=='N');
			}
			App.message({title:'{{"系统消息"|T}}',text:r.Info,time:5000,sticky:false,class_name:r.Code==1?'success':'error'});
		},'json');
	});
});
</script>
{{/Block}}